//
//  SettingsScene.cpp
//  Frog Jump
//
//  Created by acumen on 7/26/13.
//
//

#include "SettingsScene.h"

USING_NS_CC;

bool SettingsScene::init() {
    if (!CCLayer::init()) {
        return false;
    }
    CCSize winSize = GameController::getWinSize();
    pmUserDefault = CCUserDefault::sharedUserDefault();
    // Background
    CCSprite *pBackground = CCSprite::create(IMG_BACKGROUND_IPHONE_HD);
    pBackground->setAnchorPoint(CCPointZero);
    pBackground->setPosition(CCPointZero);
    addChild(pBackground);
    
    // Title
    CCLabelTTF *pTitle = CCLabelTTF::create(STR_GUIDE, FONT_TITLE, 56);
    pTitle->setPosition(CCPointMake(winSize.width/2, winSize.height/2 + 250));
    addChild(pTitle);
    
    //// Toggle for Sound
    // Sound on
    CCMenuItemLabel *pSoundOn = CCMenuItemLabel::create(CCLabelTTF::create("Sound: ON", FONT_CONTENT, 44), NULL, NULL);
    CCMenuItemLabel *pSoundOff = CCMenuItemLabel::create(CCLabelTTF::create("Sound: OFF", FONT_CONTENT, 44), NULL, NULL);
    
    CCMenuItemToggle *pToggleSound;
    if (GameController::getSoundState()) {
        pToggleSound = CCMenuItemToggle::createWithTarget(this, menu_selector(SettingsScene::menuSound_Clicked), CCArray::create(pSoundOn, pSoundOff, NULL));
    } else {
        pToggleSound = CCMenuItemToggle::createWithTarget(this, menu_selector(SettingsScene::menuSound_Clicked), CCArray::create(pSoundOff, pSoundOn, NULL));
    }
    
    
    /// Toggle for Music
    CCMenuItemLabel *pMusicOn = CCMenuItemLabel::create(CCLabelTTF::create("Music: ON", FONT_CONTENT, 44), NULL, NULL);
    CCMenuItemLabel *pMusicOff = CCMenuItemLabel::create(CCLabelTTF::create("Music: OFF", FONT_CONTENT, 44), NULL, NULL);
    
    CCMenuItemToggle *pToggleMusic;
    if (GameController::getMusicState()) {
        pToggleMusic = CCMenuItemToggle::createWithTarget(this, menu_selector(SettingsScene::menuMusic_Clicked), CCArray::create(pMusicOn, pMusicOff, NULL));
    } else {
        pToggleMusic = CCMenuItemToggle::createWithTarget(this, menu_selector(SettingsScene::menuMusic_Clicked), CCArray::create(pMusicOff, pMusicOn, NULL));
    }
    
    CCMenu *pMenu = CCMenu::create(pToggleMusic, pToggleSound, NULL);
//    pMenu->setAnchorPoint(CCPointZero);
    pMenu->setPosition(CCPointMake(winSize.width/2, 374));
    pMenu->alignItemsVerticallyWithPadding(10);
    addChild(pMenu);
    
    // Btn back
    CCMenuItemLabel *pBtnBack = CCMenuItemLabel::create(CCLabelTTF::create(STR_BACK, FONT_MENU, 56), this, menu_selector(SettingsScene::backToMenu));
    // Menu
    CCMenu *pMenuBack = CCMenu::create(pBtnBack, NULL);
    pMenuBack->setAnchorPoint(CCPointZero);
    pMenuBack->setPosition(CCPointMake(100, 64));
    addChild(pMenuBack);
    
    return true;
}

CCScene* SettingsScene::scene() {
    CCScene *pScene = CCScene::create();
    SettingsScene *pLayer = SettingsScene::create();
    pScene->addChild(pLayer);
    return pScene;
}

SettingsScene::~SettingsScene() {
    
}

